package org.zsk.cs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zsk.cs.domain.po.RightObligation;
import org.zsk.cs.domain.vo.IdentityAuthVo;
import org.zsk.cs.domain.vo.NoticeVo;
import org.zsk.cs.domain.vo.RightObligationVo;
import org.zsk.cs.response.ResultBody;
import org.zsk.cs.service.RightObligationService;
import org.zsk.fastdev.assign.Assign;

import java.util.List;

/**
 * <p>
 * 居民权利与义务 controller
 * </p>
 *
 * @author zsk
 * @version 1.0
 * Created on 2020/03/29
 */
@RestController
@RequestMapping("/rightobligation")
public class RightObligationController {
    private final RightObligationService rightObligationService;
    private final Assign assign;

    @Autowired
    public RightObligationController(RightObligationService rightObligationService, Assign assign) {
        this.rightObligationService = rightObligationService;
        this.assign = assign;
    }

    @PostMapping("/a")
    public ResultBody add(@RequestBody RightObligationVo rightObligationVo) throws Exception {
        RightObligation rightObligation=new RightObligation();
        assign.assign(rightObligationVo,rightObligation,"$districtHeadId,$content");
        rightObligationService.save(rightObligation);
        return ResultBody.success();
    }

    @PutMapping("/u")
    public ResultBody update(@RequestBody RightObligationVo rightObligationVo) throws Exception {
        RightObligation rightObligation=new RightObligation();
        assign.assign(rightObligationVo,rightObligation,"$id,$content");
        rightObligationService.updateById(rightObligation);
        return ResultBody.success();
    }

    @DeleteMapping("/d/{ids}")
    public ResultBody delete(@PathVariable List<Integer> ids) throws Exception {
        rightObligationService.removeByIds(ids);
        return ResultBody.success();
    }

    @GetMapping("/g")
    public ResultBody page(RightObligationVo rightObligationVo) throws Exception {
        Page<RightObligation> page=new Page<>();
        assign.assign(rightObligationVo,page,"$current,$size");
        return ResultBody.success(rightObligationService.page(page));
    }

    @GetMapping("/getWithUserNameByPage")
    public ResultBody getWithUserNameByPage(RightObligationVo rightObligationVo) throws Exception {
        return ResultBody.success(rightObligationService.getWithUserNameByPage(rightObligationVo));
    }

    @GetMapping("/districtHeadGetRightObligation")
    public ResultBody districtHeadGetRightObligation() throws Exception {
        return ResultBody.success(rightObligationService.districtHeadGetRightObligation());
    }

    @GetMapping("/residentGetRightObligation")
    public ResultBody residentGetRightObligation() {
        return ResultBody.success(rightObligationService.residentGetRightObligation());
    }

    @PostMapping("/districtHeadSave")
    public ResultBody districtHeadSave(@RequestBody RightObligationVo rightObligationVo) throws Exception {
        rightObligationService.districtHeadSave(rightObligationVo);
        return ResultBody.success();
    }
}
